#include "mainwindow.h"

#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QSurfaceFormat>
#include "ObjectQueue.hpp"

#include "NVM.h"
extern "C" {
#include "H_Printf.h"
}




ObjectQueue<QByteArray>* H_PrintfArray;




static void PrintfOutput(void* buffer,int length){

  H_PrintfArray->Write(new QByteArray((char*)buffer,length));

  QString str=QString::fromUtf8((char*)buffer,length);
  qDebug().noquote().nospace()<<str;
}




int main(int argc, char *argv[]){
  QApplication a(argc, argv);

  QTranslator translator;
  const QStringList uiLanguages = QLocale::system().uiLanguages();
  for (const QString &locale : uiLanguages) {
    const QString baseName = "H_NES_" + QLocale(locale).name();
    if (translator.load(":/i18n/" + baseName)) {
      a.installTranslator(&translator);
      break;
    }
  }


  H_PrintfArray=new ObjectQueue<QByteArray>(64*1024);
  H_Printf_Init(new unsigned char[1024],1024,PrintfOutput);


  NVM::Init();
  

  MainWindow w;
  w.show();

  w.LoadSettings();

  return a.exec();
}
